#include "../../include/sink.hpp"
#include "../../include/message.hpp"
#include "../../include/format.hpp"

using namespace xzt::log;

// 注意不同日志落地对象创建的传参差异性

int main()
{
    const std::string log_dir = "./logs/";
    const std::string head_filename = "log_";
    // 1) 直接创建落地对象
    // RollingBySizeFileSink sink(log_dir + head_filename, 1024 * 2);
    // 2) 利用工厂模式创建日志落地对象
    RollingBySizeFileSink::ptr sink = SinkFactory::create<RollingBySizeFileSink>(
                                            log_dir + head_filename, 1024 * 2);
    
    // 利用模板同样可以创建其他类型的日志落地对象
    auto sink_2 = SinkFactory::create<FileSink>("./logs/test.log");  // 写入到"./logs/test.log"文件中
    auto sink_3 = SinkFactory::create<StdoutSink>();
    
    for(int i = 0; i < 100000; ++i)
    {
        int level_num = i % 5;
        LogMsg msg(__FILE__, __LINE__, Level::fromNumber(level_num), "root-logger", "这是一条落地测试日志-" + std::to_string(i));
        Formatter fmt;
        std::string str = fmt.format(msg);
        sink->log(str.c_str(), str.size());
        sink_2->log(str.c_str(), str.size());
        // sink_3->log(str.c_str(), str.size());
    }

    return 0;
}